
public class MultiReceiver {
	private int numReceivers;
	private int startPort;
	private String logDir;
	private int numSecondsToWait;

	public MultiReceiver(int numReceivers, int startPort, int numSecondsToWait, String logDir) {
		this.numReceivers = numReceivers;
		this.startPort = startPort;
		this.numSecondsToWait = numSecondsToWait;
		this.logDir = logDir;
	}

	public void start() throws Exception {
		for(int i = 0; i < numReceivers; i++)
		{
			int portNumber = startPort + i;
			String logFile = logDir + "receiverLog" + (i+1) + ".txt";
			Receiver receiver = new Receiver(numSecondsToWait, portNumber, logFile);
			receiver.start();
		}
	}

	public static void main(String[] args) throws Exception {
		if (args.length != 4) {
			System.err.println("Usage: java MultiReceiver numReceivers startPort numSecondsToWait logDir");
			return;
		}

		int numReceivers = Integer.parseInt(args[0]);
		int startPort = Integer.parseInt(args[1]);
		int numSecondsToWait = Integer.parseInt(args[2]);
		String logDir = args[3];
		
		if( !(logDir.endsWith("/") || logDir.endsWith("\\")) )
		{
			System.err.println("Please provide a trailing slash for logDir");
			return;
		}
		
		MultiReceiver multiReceiver = new MultiReceiver(numReceivers, startPort, numSecondsToWait, logDir);
		multiReceiver.start();
	}
}
